/**
 * 
 */
package com.geekteam.masterenglish.ui.fragment;

import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.geekteam.masterenglish.R;
import com.geekteam.masterenglish.Adapter.ListFragmentAdapter;

/**
 * @author MTROL
 *
 */
public class HomeFragment extends BaseFragment implements ViewPager.OnPageChangeListener{
	private ViewPager mPager;
	private int mPosition;
	private List<Fragment> mListFragment;
	
	public HomeFragment(){}
	
	public HomeFragment(int position, List<Fragment> listFragments){
		this.setPosition(position);
		this.mListFragment = listFragments;
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_pager, container, false);
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		ListFragmentAdapter adapter = new ListFragmentAdapter(getChildFragmentManager(), mListFragment);
		mPager = (ViewPager) getView().findViewById(R.id.pager);
		mPager.setAdapter(adapter);
		mPager.setOffscreenPageLimit(3);
		mPager.setOnPageChangeListener(this);
	}

	public int getPosition() {
		return mPosition;
	}

	public void setPosition(int position) {
		this.mPosition = position;
		if(mPager!=null){
			mPager.setCurrentItem(mPosition, true);
		}
	}

	@Override
	public void onPageScrollStateChanged(int position) {}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {}

	@Override
	public void onPageSelected(int position) {
		mActivity.setNavigationPosition(position);
	}
}
